<?php
session_start();
header('Content-type: text/html; charset=utf-8');
include('../includes/config.php');
require_once('../classes/database.php');

/********Actualisation de la session...**********/

include('../includes/fonctions.php');
$idconnect=Database::getInstance();
actualiser_session($idconnect);

 //vérification des droits de l'utilisateur
$querytest = pg_query($idconnect,"SELECT * FROM droit_utilisateur WHERE id_droit=1 and id_user=".$_SESSION['membre_id']);
	$nb1 = pg_num_rows($querytest);
	if(!isset($_SESSION['membre_id']) || $nb1==0){
	header('Location: ../site.php');
	exit();
}
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="../style.css" />
         <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="style_ie.css" />
        <![endif]-->
        <link rel="stylesheet" href="../js/tablesorter.css" />
        <title>Base de données Microcèbes</title>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/jquery.tablesorter.js"></script>
        <script>
			function submit(user){
				document.getElementById("id_user").value=user;
				document.monForm.submit();
			}
			$(document).ready(function() {
		        $("#myTable").tablesorter();
		    });
        </script>

    </head>

    <body>

		<?php include("../menu.php"); ?>

		<section id="main">
			<header>
				<h1>Liste des utilisateurs</h1>
			</header>
			<article>
			<?php
			if(isset($_SESSION['success_message']) && $_SESSION['success_message'] != null) {
				echo "<p>".$_SESSION['success_message']."</p>";
				$_SESSION['success_message'] = null;
			}
			?>
			<br><br>
			<a href="new_account.php" class="adduser"><img src="../public/images/adduser.png"> Ajout d'utilisateur</a>
			<br><br>
				<table id="myTable" class="tablesorter">
				<thead>
					<TR>
					<TH> Nom d'utilisateur </TH>
					<TH> Nom </TH>
					<TH> E-MAIL</TH>
					<TH> Statut </TH>
					</TR>
					</thead>
					<tbody>
					<?php

					//récupération de la liste des utilisateurs
					$query = pg_query($idconnect,"SELECT login, Nom, Prenom, id_user,email,statut FROM utilisateur
					 ORDER BY login ");
					$num=pg_num_rows($query);
					if($num!=0){
						while($back=pg_fetch_assoc($query)){
							echo "<TR ALIGN=\"CENTER\">";
							echo "<TD><a href=\"#\" onclick=\"submit(".$back['id_user'].")\">".$back['login']."</a></TD>";
							echo "<TD>".$back['nom']." ".$back['prenom']."</TD>";
							echo "<TD>".$back['email']."</TD>";
							echo "<TD>".$back['statut']."</TD>";
							echo "</TR>";
						}
					}
					?>
					</tbody>
				</table>
				<form name="monForm" method="post" action="modif_user.php">
					<input type="hidden" name="id_user" id="id_user" value="">
				</form>
			</article>
		</section>
	</body>
</html>
